package com.acme.bankapp.domain.bank;

import com.acme.exceptions.NotEnoughFundsException;

@SuppressWarnings("serial")
public abstract class AbstractAccount implements Account {

	private double balance;
	private int id;
	
	private static int lastId = 0;
	
	public AbstractAccount(double balance) {
	    if (balance < 0) {
	        throw new IllegalArgumentException();
	    }
		this.balance = balance;
		this.id = lastId++;
	}
	
	public int getId() {
	    return id;
	}
	
    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public boolean equals(Object obj) {
         if (this == obj) {
             return true;
         }
         if (obj == null) {
             return false;
         }
         if (getClass() != obj.getClass()) {
             return false;
         }
         return id == ((AbstractAccount) obj).id;
    }
        
	
	public long decimalValue() {
		return Math.round(balance);
	}
	
	public double getBalance() {
		return this.balance;
	}
	
	protected void setBalance(double d) {
		this.balance = d;
	}

	public abstract void withdraw(double amount) throws NotEnoughFundsException;
	public abstract void deposit(double amount);
	
}
